package com.kwok.boot.rabbitmq.publishsubscribe.producer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    // 1.创建一个广播交换机
    @Bean
    public FanoutExchange fanoutExchange(){
        // 创建一个名称是Publish-Subscribe-Fanout-Exchange的广播交换机
        return new FanoutExchange("Publish-Subscribe-Fanout-Exchange");
    }

    // 2.创建两个队列
    @Bean
    public Queue queueOne(){
        // 创建一个名称是Publish-Subscribe-Queue-One的消息队列
        return new Queue("Publish-Subscribe-Queue-One");
    }

    @Bean
    public Queue queueTwo(){
        // 创建一个名称是Publish-Subscribe-Queue-Two的消息队列
        return new Queue("Publish-Subscribe-Queue-Two");
    }

    // 3.通过方法名把两个队列和交换机分别进行绑定
    @Bean
    public Binding bindingOne(){
        return BindingBuilder.bind(queueOne()).to(fanoutExchange());
    }

    @Bean
    public Binding bindingTwo(){
        return BindingBuilder.bind(queueTwo()).to(fanoutExchange());
    }

}
